<?php

include _ITSTOCK_INCLUDE_DIR_.'html_search.inc.php';
include _ITSTOCK_INCLUDE_DIR_.'html_message.inc.php';
include _ITSTOCK_INCLUDE_DIR_.'html_navigation.inc.php';
include _ITSTOCK_INCLUDE_DIR_.'html_links.inc.php';
include _ITSTOCK_INCLUDE_DIR_.'html_menu.inc.php';
include _ITSTOCK_INCLUDE_DIR_.'html_table_list.inc.php';

$itstock_page_info['css'] = array('main.css', 'aside.css', 'float_menu.css', 'page.css', 'table.css', 'lightbox.css', 'form_save.css');
$itstock_page_info['js'] = array('common.js', 'ajax.js', 'request.js', 'lightbox.js', 'search.js', 'settings.js');
$itstock_page_info['title'] = 'Orders - IT Stock Tool';
$itstock_page_info['menu_title'] = 'Orders';
$itstock_page_info['menu_items'] = array(
  '<label onclick="itstock_page_request(\'add_order\')">New Order</label>',
  '<label onclick="itstock_page_request(\'add_provider\')">Add Provider</label>',
  '<label onclick="itstock_page_request(\'provider\')">Providers</label>'
);
$itstock_page_info['search_page'] = 'order';

$_SESSION['on_delete']['order'] = $_SERVER['REQUEST_URI'];
$_SESSION['on_save']['order'] = $_SERVER['REQUEST_URI'];
$_SESSION['on_delete']['provider'] = $_SERVER['REQUEST_URI'];
$_SESSION['on_save']['provider'] = $_SERVER['REQUEST_URI'];

$structure = itstock_html_search_init('order');
$structure['table_headers'] = array('Purchase Date', 'Provider', 'Order', 'Items', 'Comments', '', '');
$structure['table_indexes'] = array('purchase_date', 'provider', 'order', 'items', 'comment');
$structure['table_actions'] = array(
  array( 'img' => 'img/edit.png', 'onclick' => 'itstock_page_request(\'add_order\', \'%s\')', 'title' => 'Edit', 'id' => 'id' ),
  array( 'link' => 'delete.php?type=order&id=%s', 'img' => 'img/delete.png', 'title' => 'Delete', 'id' => 'id')
);
$structure['table_error'] = 'No orders have been found.';

$prov_get = $_GET;
if(isset($prov_get['idx'])) unset($prov_get['idx']);
if(isset($prov_get['search'])) unset($prov_get['search']);
if(isset($_GET['prov'])) {
  $structure['where'][0] = 'provider_id='.itstock_decode($_GET['prov']);
}

$structure['alias'] = array(
  '*, `orders`.id',
  'SUBSTRING(comments, 1, 30) AS comment',
  '(SELECT COUNT(*) FROM order_items WHERE order_items.order_id = `orders`.id) AS items'
);

itstock_html_base_header($itstock_page_info);
echo '<div class="aside">';
itstock_structure($prov, 'provider');
$menu_title = array(
  'text' => 'All Provides',
  'url' => '?page=order'
);
itstock_html_menu_struct($prov, 'provider', 'id', 'prov', '', $menu_title, $prov_get);
echo '</div>';
echo '<div class="bside">';
itstock_html_menu_search($itstock_page_info);
echo '<table>';
itstock_html_table_list_data($structure, false, true, true);
echo '</table>';
echo '</div>';
itstock_html_base_footer();
?>
